var app = getApp(), api = app.api, is_loading_more = !1, is_no_more = !1;

Page({
  data: {
    id: 0,
    info: '',
    show: !1,
    second: 0,
    video_nums: 0,
    finish: !1,
    mch: '',
    mch_id: '',
    is_zan: 0,
    zan_count: 0,
    video_list: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (o) {
    app.page.onLoad(this, o);
    var t = this;
    t.setData({
      id: o.id,
      mch_id: o.mch_id,
    }), getApp().core.showLoading({
      title: '加载中'
    }), getApp().request({
      url: getApp().api.default.video_view,
      method: "GET",
      data: {
          id: o.id
      },
      success: function(e) {
        0 == e.code && t.setData({
          info: e.data,
          second: e.data.looktime + 's',
          video_nums: e.data.number,
          is_zan: e.data.is_zan,
          zan_count: e.data.zan_count,
        }), 0 == e.data.number && t.setData({
          second: '红包已领完'
        }),  e.data.finish == 1 && t.setData({
          finish: !0,
          second: e.data.finishtxt,
        })
      },
      complete: function() {
        getApp().core.hideLoading();
      }
    }), app.request({
      url: api.mch.mch_info,
      data: {
        mch_id: t.data.mch_id
      },
      success: function(e) { 
        0 == e.code && t.setData({
          mch: e.data
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    console.log('onReady', this.data.mch)
  },
  play: function(o) {
    var a = o.currentTarget.dataset.index;
    getApp().core.createVideoContext("video_" + this.data.show_video).pause(), this.setData({
        show_video: a,
        show: !0
    });
  },
  bindplay(e){
    this.setData({
      show: !0
    });
  },
  bindtimeupdate(e){
    var t = this, s = parseInt(e.detail.currentTime), l = t.data.info.looktime;
    var m = l - s;
    //console.log('s',m);
    if(t.data.video_nums == 0) {
      t.setData({
        second: '红包已领完',
      })
    } else if(t.data.finish == true) {
      t.setData({
        second: t.data.info.finishtxt,
      })
    } else {
      if( m == 0 ){  //倒计时到零秒时领取红包
        t.videohb()
      }else{
         0 < m && t.setData({
          second:  m + 's'
        });
      }
    }
  },
  videohb() {
    var t = this;
    app.request({
      url: api.default.video_hb,
      data: {
        id: t.data.id
      },
      success: function(e){
        if(e.code == 0) {
          wx.showToast({
            title: '恭喜完成，获得'+t.data.info.money+'元红包。',
            icon: 'none',
            duration: 3000,
            complete: function(res) {
              t.setData({
                second: e.msg,
                video_nums: e.data.number,
                show:!0,
              })
            }
          })
          
        } else {
          t.setData({
            video_nums: e.data.number,
            second: e.msg,
          });
          
        }
      }
    });
  },
  addzan() {
    var t = this;
    app.request({
      url: api.default.video_add_zan,
      data: {
        video_id: t.data.id
      },
      success: function(e) {
        0 == e.code ? t.setData({
          zan_count: e.data,
          is_zan: 1
        }) : wx.showToast({
          title: e.data,
          icon: 'none',
          duration: 1000
        })
      }
    })
  },
  Removezan() {
    var t = this;
    app.request({
      url: api.default.video_remove_zan,
      data: {
        video_id: t.data.id
      },
      success: function(e) {
        0 == e.code ? t.setData({
          zan_count: e.data,
          is_zan: 0
        }) : wx.showToast({
          title: e.data,
          icon: 'none',
          duration: 1000
        })
      }
    })
  },
  goview(e) {
    var id = e.currentTarget.dataset.id, mch_id = e.currentTarget.dataset.mch_id;
    wx.reLaunch({
      url: '/pages/video/video-view?id=' + id + '&mch_id=' + mch_id,
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})